package com.pet.server.bo.system;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;


import com.pet.framework.page.Page;
import com.pet.framework.util.Config;
import com.pet.framework.util.FileOperate;
import com.pet.framework.util.HttpClientUtils;
import com.pet.framework.util.HttpHelp;
import com.pet.role.util.Logger;
import com.pet.server.bo.common.CommonService;
import com.pet.server.dao.common.AdminDao;
import com.pet.server.po.Campaign;
import com.pet.server.po.CateBrand;
import com.pet.system.constants.ATTSystem;
import com.pet.system.util.FolderManager;

public class AdminService extends CommonService {
	private final static Logger logger = Logger.getLogger(AdminService.class);
    private AdminDao adminDao;
    
    
    
	public AdminDao getAdminDao() {
		return adminDao;
	}


	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}

	public List<CateBrand> queryCateBrand(String cate){
		return adminDao.queryCateBrand(cate);
	}
	public void saveCateBrand(String cate,List<String> brands){
		adminDao.deleteCateBrandByCate(cate);
		for(String brand:brands){
			CateBrand cb = new CateBrand();
			cb.setBrand(brand);
			cb.setCate(cate);
			saveObject(cb);
		}
	}

	/**
	 * 活动列表
	 * @param campaign
	 * @param page
	 */
	public void searchCampaign(Campaign campaign, Page page) {
		
		adminDao.searchCampaign(campaign,page);
	}

	/**
	 * 活动保存
	 * @param campaign
	 * @param img3File
	 * @param img3FileFileName
	 */
	public void savePetInfo(Campaign campaign, File img3File,String img3FileFileName) {
		if(null!=campaign){
			
			if(null!=img3File){
				String path = FolderManager.getSysUserFolder();
				String filename=FolderManager.getCurrentName(1000, img3FileFileName);
				String resPath = FileOperate.uploadFile(img3File, path, filename);
				campaign.setImgUrl(Config.getValue("ftp.url")+resPath);
			}
		
			saveObject(campaign);
		}
		
	}

	/**
	 *活动修改
	 * @param p
	 * @param campaign
	 * @param img3File
	 * @param img3FileFileName
	 */
	public void updatePetInfo(Campaign p, Campaign campaign, File img3File,String img3FileFileName) {
		if(null!=img3File){
			String path = FolderManager.getSysUserFolder();
			String filename=FolderManager.getCurrentName(1000, img3FileFileName);
			String resPath = FileOperate.uploadFile(img3File, path, filename);
			p.setImgUrl(Config.getValue("ftp.url")+resPath);
		}
		p.setClickType(campaign.getClickType());
		p.setClickUrl(campaign.getClickUrl());
		p.setParam(campaign.getParam());
		p.setPlayType(campaign.getPlayType());
		p.setSeq(campaign.getSeq());
		p.setTarget(campaign.getTarget());
		p.setText(campaign.getText());
		if(campaign.getTuiPrice()==null){
			p.setTuiPrice(99d);
		}else{
			p.setTuiPrice(campaign.getTuiPrice());
		}
		
		p.setProductId(campaign.getProductId());
		
		
		updateObject(p);
		
	}
	
	
	
	
	
}
